#include "gameOverScence.h"
#include "gameBegin.h"
#include "HelloWorldScene.h"

USING_NS_CC;

gameOverScence::gameOverScence(void)
{
}


gameOverScence::~gameOverScence(void)
{
}

Scene* gameOverScence::createScene()
{
	Scene* scene=Scene::create();
	gameOverScence* gos=gameOverScence::create();
	scene->addChild(gos);
	
	return scene;
}

bool gameOverScence::init()
{
	if (!LayerColor::initWithColor(Color4B(255,255,255,255)))
	{
		return false;
	}

	Size size=Director::getInstance()->getVisibleSize();

	auto label_1=Label::create();
	label_1->setString("GAME OVER");
	label_1->setColor(Color3B::RED);
	label_1->setSystemFontSize(40);
	this->addChild(label_1);

	label_1->setPosition(size.width/2,size.height/2+100);


	auto label_2=Label::create();
	label_2->setString("LiuJunLiang-2016`9`16");
	label_2->setColor(Color3B::BLACK);
	label_2->setSystemFontSize(20);
	this->addChild(label_2);

	label_2->setPosition(label_2->getContentSize().width/2,size.height-label_2->getContentSize().height/2);


	auto menu1=MenuItemSprite::create(Sprite::create("restart.png"),
		Sprite::create("restart.png"),
		Sprite::create("restart.png"),
		CC_CALLBACK_1(gameOverScence::onRestart,this));
	menu1->setPositionY(50);

	auto menu2=MenuItemSprite::create(Sprite::create("back.png"),
		Sprite::create("back.png"),
		Sprite::create("back.png"),
		CC_CALLBACK_1(gameOverScence::onBack,this));
	menu2->setPositionY(50);

	auto menu=Menu::create(menu1,menu2,NULL);
	menu->alignItemsHorizontallyWithPadding(100);

	this->addChild(menu);
	return true;
}


void gameOverScence::onRestart(cocos2d::Ref* ref)
{
	Director::getInstance()->replaceScene(TransitionProgressHorizontal::create(0.5,HelloWorld::createScene()));
}

void gameOverScence::onBack(cocos2d::Ref* ref)
{
	Director::getInstance()->replaceScene(TransitionProgressHorizontal::create(0.5,gameBegin::createScene()));
}
